﻿function test(tbl){
	if(isAjax()){
		return dao.query("exam",Cnd.where("course_id","=",tbl.id));
	}else{
		if(user()==null){
			return ">>:login?goto=test/"+tbl.id;
		}
		let exam_result=$fetch("exam_result",Cnd.where("user_id","=",user().id).and("tbl_id","=",tbl.id))
		print(Cnd.where("user_id","=",user().id).and("tbl_id","=",tbl.id))
		if(exam_result!=null){
			return ">>:test/result/"+exam_result.id
		}
		attr("course",$fetch("course",Cnd.where("id","=",tbl.id)))
	return dao.query("exam",Cnd.where("course_id","=",tbl.id));
	}
}
var isAjax=function(){let type = req.getHeader("X-Requested-With");if(!isEmpty(type)&&type=="XMLHttpRequest"){return true;}else return false;}